package com.hong.filter;


import org.apache.commons.text.StringEscapeUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;

public class EscapeHtmlHttpServletRequestWrapper extends HttpServletRequestWrapper {
    public EscapeHtmlHttpServletRequestWrapper(HttpServletRequest request) {
        super(request);
    }

    @Override
    public String[] getParameterValues(String parameter) {
        String[] values = super.getParameterValues(parameter);
        if (values == null) {
            return new String[0];
        }
        int count = values.length;
        String[] encodedValues = new String[count];
        for (int i = 0; i < count; i++) {
            encodedValues[i] = values[i].trim();
        }
        return encodedValues;
    }

    @Override
    public String getParameter(String parameter) {
        String param = super.getParameter(parameter);
        if (param == null) {
            return null;
        }
        return StringEscapeUtils.unescapeHtml4(param);
    }

    @Override
    public String getRequestURI() {
        String requestURI = super.getRequestURI();
        if (requestURI == null) {
            return null;
        }
        return StringEscapeUtils.unescapeHtml4(requestURI);
    }





}